package com.hjj.springboot.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hjj.springboot.entity.Notice;
import com.hjj.springboot.entity.R;
import com.hjj.springboot.service.INoticeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;

@RestController
@RequestMapping("/notice")
public class NoticeController {

    @Autowired
    private INoticeService noticeService;

    @GetMapping("/list")
    public R list(){
        Page<Notice> pageNotice = noticeService.page(new Page<>(0, 1), new QueryWrapper<Notice>().eq("isPublic", true).orderByDesc("upTime"));
        List<Notice> noticeList = pageNotice.getRecords();
        HashMap<String, Object> map = new HashMap<>();
        map.put("message", noticeList);
        return R.ok(map);
    }
}
